import { getCityInfo } from '../network/home'

// 根据城市名称查询该城市信息
export const getCurrCity = () => {
  let curCity = JSON.parse(localStorage.getItem('hkzf_city'))

  if (!curCity) {
    return new Promise((resolve, reject) => {
      try {
        const currCityNameObj = new window.BMapGL.LocalCity()
        currCityNameObj.get(async item => {
          const res = await getCityInfo('/area/info', item.name)
          localStorage.setItem('hkzf_city', JSON.stringify(res.body))
          resolve(res.body)
        })
      } catch (error) {
        reject(error)
      }
    })
  } else {
    return Promise.resolve(curCity)
  }
}